package karma.main;

import java.awt.image.BufferedImage;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;

import net.minecraft.client.Minecraft;
import net.minecraft.src.*;
import net.minecraft.src.forge.*;

public class GuiKarmaHUD extends Gui
{
	protected FontRenderer fontRenderer = ModLoader.getMinecraftInstance().fontRenderer;
	private BufferedImage holy;
    private int holyID;
    private BufferedImage hell;
    private int hellID;
    private BufferedImage c1;
    private int c1ID;
    private BufferedImage c2;
    private int c2ID;
    private BufferedImage c3;
    private int c3ID;
    private BufferedImage c4;
    private int c4ID;
    private BufferedImage c5;
    private int c5ID;
    public static boolean played = true;
    private Minecraft mc = ModLoader.getMinecraftInstance();
	
	
	public GuiKarmaHUD()
	{
		holyID = 1000;
		hellID = 1001;
		c1ID = 1002;
		c2ID = 1003;
		c3ID = 1004;
		c4ID = 1005;
		c5ID = 1006;
	}
	
	public void initGui()
	    {
	        try
	        {
	            holy = ModLoader.loadImage(mc.renderEngine, "/karma/holylegshud.png");
	            mc.renderEngine.setupTexture(holy, holyID);
	            hell = ModLoader.loadImage(mc.renderEngine, "/karma/hellbootshud.png");
	            mc.renderEngine.setupTexture(hell, hellID);
	            c1 = ModLoader.loadImage(mc.renderEngine, "/karma/c1hud.png");
	            mc.renderEngine.setupTexture(c1, c1ID);
	            c2 = ModLoader.loadImage(mc.renderEngine, "/karma/c2hud.png");
	            mc.renderEngine.setupTexture(c2, c2ID);
	            c3 = ModLoader.loadImage(mc.renderEngine, "/karma/c3hud.png");
	            mc.renderEngine.setupTexture(c3, c3ID);
	            c4 = ModLoader.loadImage(mc.renderEngine, "/karma/c4hud.png");
	            mc.renderEngine.setupTexture(c4, c4ID);
	            c5 = ModLoader.loadImage(mc.renderEngine, "/karma/c5hud.png");
	            mc.renderEngine.setupTexture(c5, c5ID);
	        }
	        catch (Exception exception)
	        {
	            exception.printStackTrace();
	        }
	}
	
	public void render(String what)
	{
		initGui(); 
		Minecraft minecraft = ModLoader.getMinecraftInstance();
	     World world = minecraft.theWorld;
	     EntityPlayer entityplayer = minecraft.thePlayer;
	     ScaledResolution scaledresolution = new ScaledResolution(minecraft.gameSettings, minecraft.displayWidth, minecraft.displayHeight);
	     int width = scaledresolution.getScaledWidth();
	     int height = scaledresolution.getScaledHeight();
	     minecraft.entityRenderer.setupOverlayRendering();
	     GL11.glEnable(GL11.GL_BLEND);
	     GL11.glEnable(GL12.GL_RESCALE_NORMAL);
	     RenderHelper.enableStandardItemLighting();
	     RenderHelper.disableStandardItemLighting();
	     GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
	     
	     if(what.equals("hellboots"))
	     {
	    	 try
	         {
	             int k = mc.renderEngine.getTexture("/karma/hellbootshud.png");
	             GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
	             mc.renderEngine.bindTexture(k);
	             drawTexturedModalRect(width - 52, height - 27, 0, 0, 47, 22);
	         }
	         finally { }
	         String s;
	         if (ItemHellBoots.cooldown == 0)
	         {
	        	 s = "OK";
	         }
	         else
	         {
	        	 int q = ((int)(ItemHellBoots.cooldown / 20)) + 1;
	        	 s = "" + q;
	         }
	         drawCenteredString(fontRenderer, s, width - 24, height - 19, 0xffffff);
	     }
	     if (what.equals("holylegs"))
	     {
	    	 int a;
	    	 int b;
	    	 if (ItemHellBoots.worn)
	    	 {
	    		 a = 49;
	    		 b = 41;
	    	 }
	    	 else
	    	 {
	    		 a = 27;
	    		 b = 19;
	    	 }
	    	
	    	 
	    	 try
	         {
	             int k = mc.renderEngine.getTexture("/karma/holylegshud.png");
	             GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
	             mc.renderEngine.bindTexture(k);
	             drawTexturedModalRect(width - 52, height - a, 0, 0, 47, 22);
	         }
	         finally { }
	         String s;
	         if (ItemHolyLegs.cooldown == 0)
	         {
	        	 s = "OK";
	         }
	         else
	         {
	        	 int q = ((int)(ItemHolyLegs.cooldown / 20)) + 1;
	        	 s = "" + q;
	         }
	         drawCenteredString(fontRenderer, s, width - 24, height - b, 0xffffff);
	     }
	     if (what.equals("channeltp"))
	     {
	    	 double d = GuiTeleAmulet.channeltimer;
	         drawCenteredString(fontRenderer, "Channeling...", width / 2 - 2, height - 80, 0xffffff);
	         if (!played)
	         {
	        	 entityplayer.worldObj.playSoundEffect(entityplayer.posX, entityplayer.posY, entityplayer.posZ, "portal.trigger", 1.0F, 1.0F);
	        	 played = true;
	         }
	         if (d < 5)
	         {
	        	 try
		         {
		             int k = mc.renderEngine.getTexture("/karma/c1hud.png");
		             GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
		             mc.renderEngine.bindTexture(k);
		             drawTexturedModalRect(width / 2 - 24, height - 70, 0, 0, 48, 22);
		         }
		         finally { }
	         }
	         else if (d < 10)
	         {
	        	 try
		         {
		             int k = mc.renderEngine.getTexture("/karma/c2hud.png");
		             GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
		             mc.renderEngine.bindTexture(k);
		             drawTexturedModalRect(width / 2 - 24, height - 70, 0, 0, 48, 22);
		         }
		         finally { }
	         }
	         else if (d < 15)
	         {
	        	 try
		         {
		             int k = mc.renderEngine.getTexture("/karma/c3hud.png");
		             GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
		             mc.renderEngine.bindTexture(k);
		             drawTexturedModalRect(width / 2 - 24, height - 70, 0, 0, 48, 22);
		         }
		         finally { }
	         }
	         else if (d < 20)
	         {
	        	 try
		         {
		             int k = mc.renderEngine.getTexture("/karma/c4hud.png");
		             GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
		             mc.renderEngine.bindTexture(k);
		             drawTexturedModalRect(width / 2 - 24, height - 70, 0, 0, 48, 22);
		         }
		         finally { }
	         }
	         else if (d <= 25)
	         {
	        	 try
		         {
		             int k = mc.renderEngine.getTexture("/karma/c5hud.png");
		             GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
		             mc.renderEngine.bindTexture(k);
		             drawTexturedModalRect(width / 2 - 24, height - 70, 0, 0, 48, 22);
		         }
		         finally { }
	         }
	     }
	}
}
